<?php
/*
 * 1626cms 企業用戶相關
 * ============================================================================
 * 版權所有: 1626網絡，并保留所有權利。
 * 網站地址: http://www.1626.com；
 * ----------------------------------------------------------------------------
 * 這不是一個自由軟件！您只能在不用于商業目的的前提下對程序代碼進行修改和
 * 使用；不允許對程序代碼以任何形式任何目的的再發布。
 * ============================================================================
 */
define('IN_QISHI', true);
require_once('../data/config.php');
require_once('./include/admin_common.inc.php');
require_once(ADMIN_ROOT_PATH.'include/admin_member_personal_fun.php');
!empty($_POST['perpage'])?(setcookie('perpage',intval($_POST['perpage']))).($perpage=intval($_POST['perpage'])):($perpage= !empty($_COOKIE['perpage'])? $_COOKIE['perpage'] :'10');
$act = !empty($_GET['act']) ? trim($_GET['act']) : 'list';
//*****************************************簡歷列表************************
if($act == 'list'){
	require_once(ADMIN_ROOT_PATH.'include/page.class.php');
	require_once(ADMIN_ROOT_PATH.'include/admin_fun_category.php');
	//按月查看
	if($_GET['dateline'])
	{
		$dateline= time() - 30 * 24 * 3600;
		$joinsql = " addtime > $dateline ";
	}
	!empty($_GET['audit']).(trim($_GET['audit'])+0!=0)? $wheresqlarr['audit']=trim($_GET['audit']):'';
	//!empty($_GET['display']).(trim($_GET['display'])+0!=0)? $wheresqlarr['display']=trim($_GET['display']):'';
	!empty($_GET['talent']).(trim($_GET['talent'])+0!=0)? $wheresqlarr['talent']=trim($_GET['talent']):'';
	!empty($_GET['photoresume']).(trim($_GET['photoresume'])+0!=0)? $wheresqlarr['photoresume']=trim($_GET['photoresume']):'';
	if ($_GET['photoresume']=="2")//假如選擇有照片的刪選，才能開啟照片審核狀態的選項
	{
		!empty($_GET['photo_audit']).(trim($_GET['photo_audit'])+0!=0)? $wheresqlarr['photo_audit']=trim($_GET['photo_audit']):'';
	}
	if (is_array($wheresqlarr))
	{
		$where_set=' WHERE';
		foreach ($wheresqlarr as $key => $value)
		{
			$wheresql .=$where_set. $comma.'`'.$key.'`'.'=\''.$value.'\'';
			$comma = ' AND ';
			$where_set='';
		}
	}
	$key=trim($_POST['key']);
	!empty($key)?($wheresql=" WHERE fullname like '%{$key}%'"):'';
	if($joinsql){
		if($wheresql){
			$wheresql = $wheresql .' AND ' . $joinsql;
		}else
		{
			$wheresql = ' WHERE ' . $joinsql;
		}
	}
	$total_sql="SELECT COUNT(*) AS num FROM ".table('resume').$wheresql;
	$total_val=get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$list = get_resume_list($offset,$perpage,$wheresql);
	$smarty->assign('pageheader',"管理中心 - 簡歷列表");
	$smarty->assign('audit',$_GET['audit']);//審核狀態
	//$smarty->assign('display',$_GET['display']);//公開狀態
	$smarty->assign('talent',$_GET['talent']);//人才等級
	$smarty->assign('photoresume',$_GET['photoresume']);//照片人才
	$smarty->assign('photo_audit',$_GET['photo_audit']);//照片審核狀態
	$smarty->assign('dateline',$_GET['dateline']);//時間範圍
	$smarty->assign('key',$key);//關鍵字POST
	$smarty->assign('resume_photo_dir_thumb',$resume_photo_dir_thumb);//個人照片縮略圖存放目錄
	$smarty->assign('perpage',$perpage);//每頁顯示數量POST
	$smarty->assign('list',$list);//列表
	if ($total_val>$perpage)
	{
		$smarty->assign('page',$page->show(3));//分頁符
	}
	$smarty->display('admin_member_personal_resume.htm');
}
//刪除，更改審核狀態，更改人才等級
if($act == 'perform'){
	$yid =trim($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你沒有選擇簡歷！",1);
	$delete =trim($_REQUEST['delete']);
	$link[0]['text'] = "返回上一頁";
	$link[0]['href'] = $_SERVER['HTTP_REFERER'];
	echo ("<script>window.parent.leftFrame.location.href='admin_index.php?act=left';</script>");
	$delete?(!del_resume($yid)?showmsg("刪除失敗！",0,$link):showmsg("刪除成功！",2,$link)):'';
	trim($_REQUEST['audit1'])?(!edit_resume_audit($yid,1)?showmsg("設置失敗！",0):showmsg("設置成功！",2,$link)):'';
	trim($_REQUEST['audit3'])?(!edit_resume_audit($yid,3)?showmsg("設置失敗！",0):showmsg("設置成功！",2,$link)):'';
	trim($_REQUEST['talent1'])?(!edit_resume_talent($yid,1)?showmsg("設置失敗！",0):showmsg("設置成功！",2,$link)):'';
	trim($_REQUEST['talent2'])?(!edit_resume_talent($yid,2)?showmsg("設置失敗！",0):showmsg("設置成功！",2,$link)):'';
	trim($_REQUEST['photoaudit1'])?(!edit_resume_photoaudit($yid,1)?showmsg("設置失敗！",0):showmsg("設置成功！",2,$link)):'';
	trim($_REQUEST['photoaudit3'])?(!edit_resume_photoaudit($yid,3)?showmsg("設置失敗！",0):showmsg("設置成功！",2,$link)):'';
}
//*****************************************參數設置************************
//企業用戶區參數設置
if($act == 'set'){
	$smarty->assign('pageheader',"管理中心 - 個人用戶相關設置");
	$smarty->assign('config',get_cache('config',true));
	$smarty->display('admin_member_personal_set.htm');
}
//保存--企業用戶區參數設置
if($act == 'set_save'){
	foreach($_POST as $k => $v){
		!$db->query("UPDATE ".table("config")." SET value='".$v."' WHERE name='$k'")?showmsg('更新設置失敗', 1):"";
	}
	get_cache('config',true);
	showmsg("保存成功！",2);
}
//*****************************************個人用戶區會員************************
//個人會員列表
if($act == 'members_list'){
	require_once(ADMIN_ROOT_PATH.'include/page.class.php');
	$key=trim($_POST['key']);
	$wheresql=" WHERE uid IN (SELECT uid FROM ".table('members_type')." WHERE utype='2')";
	if ($key) $wheresql.=" AND ( username like '%{$key}%' OR email like '%{$key}%')";
	$wheresql.=" ORDER BY uid desc ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('members').$wheresql;
	$total_val=get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$list = get_member_list($offset,$perpage,$wheresql);
	$smarty->assign('pageheader',"管理中心 - 個人會員列表");
	$smarty->assign('key',$key);//狀態
	$smarty->assign('perpage',$perpage);//每頁顯示數量POST
	$smarty->assign('list',$list);//列表
	if ($total_val>$perpage)
	{
		$smarty->assign('page',$page->show(3));//分頁符
	}
	$smarty->display('admin_member_personal_user_list.htm');
}
//刪除會員
if($act == 'delete_user'){
	$u_id =trim($_POST['y_id'])?$_POST['y_id']:showmsg("你沒有選擇會員！",1);
	if ($_POST['delete'])
	{
		trim($_POST['delete_user'])==='yes'?(!delete_member($u_id)?showmsg("刪除會員失敗！",0).(exit()):""):'';
		trim($_POST['delete_resume'])==='yes'?(!del_resume($u_id)?showmsg("刪除失敗！",0).(exit()):""):'';
		showmsg("刪除成功！",2);
	}
}
//編輯會員
if($act == 'user_edit'){
	$smarty->assign('pageheader',"管理中心 - 個人會員 - 修改");
	$smarty->assign('personal_user',get_member_one($_GET['memberuid']));
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->display('admin_member_personal_user_edit.htm');
}
//修改會員的密碼
if($act == 'userpass_edit'){
	if (strlen(trim($_POST['password']))<6) showmsg('新密碼必須為6位以上！',1);
	if ($_POST['password']!=$_POST['password1']) showmsg('兩次輸入的密碼不同',1);
	$user_info=get_member_one($_POST['memberuid']);
	$pwd_hash=$user_info['pwd_hash'];
	$md5password=md5(md5(trim($_POST['password'])).$pwd_hash);
	if ($db->query( "UPDATE ".table('members')." SET password = '$md5password'  WHERE uid='".$user_info['uid']."'"))
	{
		$link[0]['text'] = "返回列表";
		$link[0]['href'] = $_POST['url'];
		showmsg('操作成功！',2,$link);
	}
	else
	{
		showmsg('操作失敗！',1);
	}
}
//添加會員
if($act == 'members_add'){
	$smarty->assign('pageheader',"管理中心 - 個人會員 - 添加個人會員");
	$smarty->display('admin_member_personal_user_add.htm');
}
//保存添加會員
if($act == 'members_add_save'){
	require_once(ADMIN_ROOT_PATH.'include/admin_user_fun.php');
	$add_username = !empty($_POST['username']) ? trim($_POST['username']):showmsg('請填寫用戶名！',1);
	$add_password = !empty($_POST['password']) ? trim($_POST['password']):showmsg('請填寫密碼！',1);
	if (strlen(trim($_POST['username']))<3) showmsg('用戶名必須為3位以上！',1);
	if (strlen(trim($_POST['password']))<6) showmsg('密碼必須為6位以上！',1);
	($add_password<>trim($_POST['password1']))? showmsg('兩次輸入的密碼不相同！',1):'';
	$add_member_type = !empty($_POST['member_type']) ? trim($_POST['member_type']):showmsg('你沒有選擇注冊類型！',1);
	$add_email = !empty($_POST['email']) ? trim($_POST['email']):showmsg('請填寫電子郵箱！',1);
	if (empty($add_email) || !ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$add_email))showmsg('電子郵箱格式錯誤！',1);
	(!is_numeric($add_member_type)||$add_member_type+0==0)?showmsg('注冊出錯！',0):'';
	$ck_user=get_company_user($add_username);
	$ck_user?showmsg('該用戶名已經被使用！',1):'';
	$ck_email=get_company_user($add_email);
	$ck_email?showmsg('該 Email 已經被注冊！',1):'';
	if (!$ck_user && !$ck_email)
	{
		$pwd_hash=randstr();
		$password_hash=md5(md5($add_password).$pwd_hash);
		$sql = "INSERT INTO ".table('members')." (username,password,pwd_hash,email,reg_time,reg_ip) VALUES ('$add_username','$password_hash','$pwd_hash', '$add_email', '$timestamp','$online_ip')";
		$db->query($sql);
		$insert_id=$db->insert_id();
		$sql1 = "INSERT INTO ".table('members_type')." (uid,utype) VALUES ('$insert_id','$add_member_type')";
		$db->query($sql1);
		if($member_type==1)
		{
			$sql2 = "INSERT INTO ".table('members_points')." (uid) VALUES ('$insert_id')";
			$db->query($sql2);
			$_CFG['reg_points']>0?report_deal($insert_id,1,$_CFG['reg_points'],'<span style=color:#FF6600>注冊會員系統自動贈送!</span>'):'';
		}}
		$link[0]['text'] = "返回列表";
		$link[0]['href'] = "?act=members_list";
		showmsg('添加成功！',2,$link);
}
?>
